package JDBC1;
import com.mysql.jdbc.Driver;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class Demo3 {


        public static void main(String[] args) throws SQLException, ClassNotFoundException {
            //Driver driver=new Driver();
            //DriverManager.registerDriver(driver);
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root");
            //System.out.println(connection);
            String sql="SELECT * FROM student";
            Statement statement= connection.createStatement();
            ResultSet set= statement.executeQuery(sql);
            System.out.println(set);
            List<StudentJDBC> list=new ArrayList<StudentJDBC>();
            while(set.next())
            {
                int id=set.getInt("id");
                String name=set.getString("name");
                int age=set.getInt("age");
                String gander=set.getString("gander");
                String address=set.getString("address");
                list.add(new StudentJDBC(id,name,age,gander,address));
                // System.out.println("student :"+id+","+name+","+age+","+gander+","+address);
            }
            for (StudentJDBC i:list) {
                System.out.println(i);
            }
            statement.close();
            connection.close();
        }
    }
    class StudentJDBC {
        private int id;
        private String name;
        private int age;
        private String gander;
        private String address;


        public StudentJDBC(int id, String name, int age, String gander, String address) {
            this.id = id;
            this.name = name;
            this.age = age;
            this.gander = gander;
            this.address = address;
        }

        public StudentJDBC() {
        }

        @Override
        public String toString() {
            return "StudentJDBC{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", age=" + age +
                    ", gander='" + gander + '\'' +
                    ", address='" + address + '\'' +
                    '}';
        }
    }